package com.jml.AOP004.Log;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @author:jml
 * @date: 2019/9/24 14:38
 * @description：
 */
@Aspect
@Component
@EnableAspectJAutoProxy//开启AOP
public class LogAop {
	
	//定义切入点
	@Pointcut("execution (* com.jml.AOP004.service..*.*(..))")
	public void logAop() {
	
	}
	
	//前置通知
	@Before("logAop()")
	public void doBefore() {
		System.out.println("前置通知");
	}
	
	//后置通知
	@After("logAop()")
	public void doAfter() {
		System.out.println("后置通知001");
	}
	
	@AfterReturning("logAop()")
	public void doAfterReturning(JoinPoint joinPoint) {
		System.out.println("运行通知");
	}
	
	@AfterThrowing("logAop()")
	public void doAfterThrowing(JoinPoint joinPoint) {
		System.out.println("异常通知");
	}
	
	@Around("logAop()")
	public void doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
		System.out.println("环绕通知1");
		proceedingJoinPoint.proceed();//执行代码
		System.out.println("环绕通知2");
	}
	
}
